package com.programmercarl.dp;

/**
 * https://leetcode.cn/problems/min-cost-climbing-stairs/description/
 * 746. 使用最小花费爬楼梯 AC
 *
 * @author yulongtian
 * @create 2025-02-11 22:28
 */
public class Test03 {
    public static void main(String[] args) {
        Test03 test03 = new Test03();
        System.out.println(test03.minCostClimbingStairs(new int[]{1, 100, 1, 1, 1, 100, 1, 1, 100, 1}));
    }

    public int minCostClimbingStairs(int[] cost) {
        if (cost.length == 2) {
            return Math.min(cost[0], cost[1]);
        }
        int[] dp = new int[cost.length];
        dp[0] = cost[0];
        dp[1] = cost[1];
        for (int i = 2; i < cost.length; i++) {
            dp[i] = Math.min(dp[i - 1] + cost[i], dp[i - 2] + cost[i]);
        }

        return Math.min(dp[cost.length - 1], dp[cost.length - 2]);
    }

}
